/**
 * Copyright 1999-2015 dangdang.com.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </p>
 */

package spring.cloud.tasks.api.service;

import spring.cloud.tasks.api.domain.ExecutorAllocatInfo;
import spring.cloud.tasks.api.domain.ExecutorInfo;
import spring.cloud.tasks.api.domain.ExecutorRunningInfo;
import spring.cloud.tasks.api.domain.TaskExecutorStatus12;

import java.util.List;

/**
 * Executor 相关的服务
 */
public interface ExecutorService {

    /**
     * 获取所有Executors信息；
     *
     * @param namespace 域
     * @return executor信息, 如果不存在则返回空的<code>java.util.List</code>；
     */
    List<ExecutorInfo> getExecutorInfoList(String namespace) throws RuntimeException;

    /**
     * 获取特定状态的Executors信息；
     *
     * @param namespace 域
     * @return executor信息, 如果不存在则返回空的<code>java.util.List</code>；
     */
    List<ExecutorInfo> getExecutorInfoList(String namespace, TaskExecutorStatus12 serverStatus) throws RuntimeException;

    /**
     * 获取单个Executors信息；
     *
     * @param namespace    域
     * @param executorName 目标executor
     * @return executor信息, 如果不存在则返回<code>null</code>；
     */
    ExecutorInfo getExecutorInfo(String namespace, String executorName) throws RuntimeException;

    /**
     * 获取Executor所分配的分片信息；
     *
     * @param namespace    域
     * @param executorName 目标executor
     * @return executor分配信息
     */
    ExecutorAllocatInfo getExecutorAllocation(String namespace, String executorName)
            throws RuntimeException;


    /**
     * 获取Executor上所有正在运行的作业分片信息.
     *
     * @param namespace    域
     * @param executorName 目标executor
     * @return executor所有运行中的分片信息
     * @throws RuntimeException
     */
    ExecutorRunningInfo getExecutorRunningInfo(String namespace, String executorName) throws RuntimeException;

    /**
     * 移除离线的executor.
     *
     * @param namespace    域
     * @param executorName 目标executor
     */
    void removeExecutor(String namespace, String executorName) throws RuntimeException;

    /**
     * 摘取流量
     *
     * @param namespace    域
     * @param executorName 目标executor
     */
    void extractTraffic(String namespace, String executorName) throws RuntimeException;

    /**
     * 恢复流量
     *
     * @param namespace    域
     * @param executorName 目标executor
     */
    void recoverTraffic(String namespace, String executorName) throws RuntimeException;

    /**
     * 重shard域下所有作业分片
     *
     * @param namespace 域
     */
    void shardAll(String namespace) throws RuntimeException;


    /**
     * 一键restart。
     *
     * @param namespace    域
     * @param executorName 目标executor
     */
    void restart(String namespace, String executorName) throws RuntimeException;
}
